#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	const int MAX = 1001;
	char sequence[MAX];
	char result[2 * MAX];
	int numberOfTests;
	scanf("%d", &numberOfTests);

	int radix = 10;

	for (int k = 0; k < numberOfTests; k++) {
		scanf("%s", sequence);
		int seqLen = strlen(sequence);

		memset(result, 0, 2 * MAX);
		int resultIndex = 0;
		int num = 0;
		for (int i = 0; i < seqLen;) {
			num = 1;
			int j = i + 1;
			while (sequence[j] == sequence[i] && j < seqLen) {
				++num;
				++j;
			}

			int power = 1;
			while (num / power > 0) {
				power *= radix;
			}
			power /= radix;
			while (power > 0) {
				int digit = num / power;
				result[resultIndex++] = digit + '0';
				//num = (num - digit) / 10;
				num %= power;
				power /= radix;
			}
			result[resultIndex++] = sequence[i]; 

			i = j;
		}

		printf("%s\n", result);

	}
	return 0;
}